// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file relative_path_includeTypeObjectSupport.cxx
 * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
 *
 * This file was generated by the tool fastddsgen.
 */

#include "relative_path_includeTypeObjectSupport.hpp"

#include <mutex>
#include <string>

#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>

#include "relative_path_include.hpp"

#include "../IDL/helpers/basic_inner_types.hpp"

using namespace eprosima::fastdds::dds::xtypes;

void register_relative_path_include_type_objects()
{
    static std::once_flag once_flag;
    std::call_once(once_flag, []()
            {
                TypeIdentifier type_id;
                register_InnerStructureHelper_type_identifier(type_id);

                register_InnerEmptyStructureHelper_type_identifier(type_id);

                register_InnerUnionHelper_type_identifier(type_id);

                register_RelativePathIncludeStruct_type_identifier(type_id);

            });
}

// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_RelativePathIncludeStruct_type_identifier(
        TypeIdentifier& type_id)
{
    {
        StructTypeFlag struct_flags_RelativePathIncludeStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED,
                false, false);
        ReturnCode_t return_code_RelativePathIncludeStruct;
        TypeIdentifierPair type_ids_RelativePathIncludeStruct;
        QualifiedTypeName type_name_RelativePathIncludeStruct = "RelativePathIncludeStruct";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_RelativePathIncludeStruct;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_RelativePathIncludeStruct;
        CompleteTypeDetail detail_RelativePathIncludeStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_RelativePathIncludeStruct, ann_custom_RelativePathIncludeStruct, type_name_RelativePathIncludeStruct.to_string());
        CompleteStructHeader header_RelativePathIncludeStruct;
        header_RelativePathIncludeStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_RelativePathIncludeStruct);
        CompleteStructMemberSeq member_seq_RelativePathIncludeStruct;
        {
            return_code_RelativePathIncludeStruct =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "InnerEnumHelper", type_ids_RelativePathIncludeStruct);

            if (return_code_RelativePathIncludeStruct != eprosima::fastdds::dds::RETCODE_OK)
            {
                EnumTypeFlag enum_flags_InnerEnumHelper = 0;
                BitBound bit_bound_InnerEnumHelper = 32;
                CommonEnumeratedHeader common_InnerEnumHelper = TypeObjectUtils::build_common_enumerated_header(bit_bound_InnerEnumHelper);
                QualifiedTypeName type_name_InnerEnumHelper = "InnerEnumHelper";
                eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_InnerEnumHelper;
                eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_InnerEnumHelper;
                CompleteTypeDetail detail_InnerEnumHelper = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_InnerEnumHelper, ann_custom_InnerEnumHelper, type_name_InnerEnumHelper.to_string());
                CompleteEnumeratedHeader header_InnerEnumHelper = TypeObjectUtils::build_complete_enumerated_header(common_InnerEnumHelper, detail_InnerEnumHelper);
                CompleteEnumeratedLiteralSeq literal_seq_InnerEnumHelper;
                {
                    EnumeratedLiteralFlag flags_ENUM_VALUE_1 = TypeObjectUtils::build_enumerated_literal_flag(false);
                    CommonEnumeratedLiteral common_ENUM_VALUE_1 = TypeObjectUtils::build_common_enumerated_literal(0, flags_ENUM_VALUE_1);
                    eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE_1;
                    ann_custom_InnerEnumHelper.reset();
                    MemberName name_ENUM_VALUE_1 = "ENUM_VALUE_1";
                    CompleteMemberDetail detail_ENUM_VALUE_1 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE_1, member_ann_builtin_ENUM_VALUE_1, ann_custom_InnerEnumHelper);
                    CompleteEnumeratedLiteral literal_ENUM_VALUE_1 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE_1, detail_ENUM_VALUE_1);
                    TypeObjectUtils::add_complete_enumerated_literal(literal_seq_InnerEnumHelper, literal_ENUM_VALUE_1);
                }
                {
                    EnumeratedLiteralFlag flags_ENUM_VALUE_2 = TypeObjectUtils::build_enumerated_literal_flag(false);
                    CommonEnumeratedLiteral common_ENUM_VALUE_2 = TypeObjectUtils::build_common_enumerated_literal(1, flags_ENUM_VALUE_2);
                    eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE_2;
                    ann_custom_InnerEnumHelper.reset();
                    MemberName name_ENUM_VALUE_2 = "ENUM_VALUE_2";
                    CompleteMemberDetail detail_ENUM_VALUE_2 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE_2, member_ann_builtin_ENUM_VALUE_2, ann_custom_InnerEnumHelper);
                    CompleteEnumeratedLiteral literal_ENUM_VALUE_2 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE_2, detail_ENUM_VALUE_2);
                    TypeObjectUtils::add_complete_enumerated_literal(literal_seq_InnerEnumHelper, literal_ENUM_VALUE_2);
                }
                {
                    EnumeratedLiteralFlag flags_ENUM_VALUE_3 = TypeObjectUtils::build_enumerated_literal_flag(false);
                    CommonEnumeratedLiteral common_ENUM_VALUE_3 = TypeObjectUtils::build_common_enumerated_literal(2, flags_ENUM_VALUE_3);
                    eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE_3;
                    ann_custom_InnerEnumHelper.reset();
                    MemberName name_ENUM_VALUE_3 = "ENUM_VALUE_3";
                    CompleteMemberDetail detail_ENUM_VALUE_3 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE_3, member_ann_builtin_ENUM_VALUE_3, ann_custom_InnerEnumHelper);
                    CompleteEnumeratedLiteral literal_ENUM_VALUE_3 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE_3, detail_ENUM_VALUE_3);
                    TypeObjectUtils::add_complete_enumerated_literal(literal_seq_InnerEnumHelper, literal_ENUM_VALUE_3);
                }
                CompleteEnumeratedType enumerated_type_InnerEnumHelper = TypeObjectUtils::build_complete_enumerated_type(enum_flags_InnerEnumHelper, header_InnerEnumHelper,
                        literal_seq_InnerEnumHelper);
                if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                        TypeObjectUtils::build_and_register_enumerated_type_object(enumerated_type_InnerEnumHelper, type_name_InnerEnumHelper.to_string()))
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "InnerEnumHelper already registered in TypeObjectRegistry for a different type.");
                }
                return_code_RelativePathIncludeStruct =
                    eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                    "InnerEnumHelper", type_ids_RelativePathIncludeStruct);
                if (return_code_RelativePathIncludeStruct != eprosima::fastdds::dds::RETCODE_OK)
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                                "InnerEnumHelper: Given Enum TypeIdentifier unknown to TypeObjectRegistry.");
                    type_id = TypeIdentifier();
                    return;
                }
            }
            StructMemberFlag member_flags_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
                    false, false, false, false);
            CommonStructMember common_value;
            MemberId member_id_value = 0x00000000;
            if (EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1()._d() || TK_NONE == type_ids_RelativePathIncludeStruct.type_identifier2()._d() ||
                    (TI_PLAIN_SEQUENCE_SMALL == type_ids_RelativePathIncludeStruct.type_identifier1()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().seq_sdefn().header().equiv_kind()) ||
                    (TI_PLAIN_SEQUENCE_LARGE == type_ids_RelativePathIncludeStruct.type_identifier1()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().seq_ldefn().header().equiv_kind()) ||
                    (TI_PLAIN_ARRAY_SMALL == type_ids_RelativePathIncludeStruct.type_identifier1()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().array_sdefn().header().equiv_kind()) ||
                    (TI_PLAIN_ARRAY_LARGE == type_ids_RelativePathIncludeStruct.type_identifier1()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().array_ldefn().header().equiv_kind()) ||
                    (TI_PLAIN_MAP_SMALL == type_ids_RelativePathIncludeStruct.type_identifier1()._d() &&
                    (EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().map_sdefn().header().equiv_kind() ||
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().map_sdefn().key_identifier()->_d())) ||
                    (TI_PLAIN_MAP_LARGE == type_ids_RelativePathIncludeStruct.type_identifier1()._d() &&
                    (EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().map_ldefn().header().equiv_kind() ||
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier1().map_ldefn().key_identifier()->_d())))
            {
                common_value = TypeObjectUtils::build_common_struct_member(member_id_value, member_flags_value, type_ids_RelativePathIncludeStruct.type_identifier1());
            }
            else if (EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2()._d() ||
                    (TI_PLAIN_SEQUENCE_SMALL == type_ids_RelativePathIncludeStruct.type_identifier2()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().seq_sdefn().header().equiv_kind()) ||
                    (TI_PLAIN_SEQUENCE_LARGE == type_ids_RelativePathIncludeStruct.type_identifier2()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().seq_ldefn().header().equiv_kind()) ||
                    (TI_PLAIN_ARRAY_SMALL == type_ids_RelativePathIncludeStruct.type_identifier2()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().array_sdefn().header().equiv_kind()) ||
                    (TI_PLAIN_ARRAY_LARGE == type_ids_RelativePathIncludeStruct.type_identifier2()._d() &&
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().array_ldefn().header().equiv_kind()) ||
                    (TI_PLAIN_MAP_SMALL == type_ids_RelativePathIncludeStruct.type_identifier2()._d() &&
                    (EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().map_sdefn().header().equiv_kind() ||
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().map_sdefn().key_identifier()->_d())) ||
                    (TI_PLAIN_MAP_LARGE == type_ids_RelativePathIncludeStruct.type_identifier2()._d() &&
                    (EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().map_ldefn().header().equiv_kind() ||
                    EK_COMPLETE == type_ids_RelativePathIncludeStruct.type_identifier2().map_ldefn().key_identifier()->_d())))
            {
                common_value = TypeObjectUtils::build_common_struct_member(member_id_value, member_flags_value, type_ids_RelativePathIncludeStruct.type_identifier2());
            }
            else
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "Structure value member TypeIdentifier inconsistent.");
                type_id = TypeIdentifier();
                return;
            }
            MemberName name_value = "value";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_value;
            ann_custom_RelativePathIncludeStruct.reset();
            CompleteMemberDetail detail_value = TypeObjectUtils::build_complete_member_detail(name_value, member_ann_builtin_value, ann_custom_RelativePathIncludeStruct);
            CompleteStructMember member_value = TypeObjectUtils::build_complete_struct_member(common_value, detail_value);
            TypeObjectUtils::add_complete_struct_member(member_seq_RelativePathIncludeStruct, member_value);
        }
        CompleteStructType struct_type_RelativePathIncludeStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_RelativePathIncludeStruct, header_RelativePathIncludeStruct, member_seq_RelativePathIncludeStruct);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_RelativePathIncludeStruct, type_name_RelativePathIncludeStruct.to_string(), type_id))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "RelativePathIncludeStruct already registered in TypeObjectRegistry for a different type.");
        }
        return_code_RelativePathIncludeStruct =
            eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
            "RelativePathIncludeStruct", type_ids_RelativePathIncludeStruct);
        if (return_code_RelativePathIncludeStruct != eprosima::fastdds::dds::RETCODE_OK)
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "RelativePathIncludeStruct: Given Struct TypeIdentifier unknown to TypeObjectRegistry.");
            type_id = TypeIdentifier();
            return;
        }
    }
}

